<template>
	<BaseContainer>
		<el-tabs v-model="activeName" class="demo-tabs" @tab-click="onTabClick" tabPosition="left" :beforeOnLoadFormate="beforeOnLoadFormate">
			<el-tab-pane v-for="(item, index) in tabs" :key="index" :label="item.label" :name="item.name"> </el-tab-pane>
			<el-tabs v-model="typeActive" class="demo-tabs">
					<el-tab-pane label="采集明细" name="a" v-if="activeName !== '9'&&permissionsObj['gather_detail']">
						<GatherDetail v-if="typeActive == 'a'" :key="activeName" :tableName="tableName" dataStatus="2"></GatherDetail>
					</el-tab-pane>
					<el-tab-pane label="采集批次" :name="activeName == '9' ? 'a' : 'b'" v-if="permissionsObj['gather_batch']">
						<RecordPage :key="activeName" :dataType="activeName" v-if="typeActive == 'b' || activeName == '9'"></RecordPage>
					</el-tab-pane >
				<tempalte >
					<el-tab-pane label="采集统计" name="c" v-if="activeName !== '9'&&permissionsObj['gather_statistics']">
						<Statistics :key="activeName" :dataType="tabs[Number(activeName) - 1].tableName" v-if="typeActive == 'c'"></Statistics>
					</el-tab-pane>
				</tempalte>
			</el-tabs>
		</el-tabs>
	</BaseContainer>
</template>

<script setup lang="ts">
import RecordPage from './record.vue'
import GatherDetail from './GatherDetail/index.vue'
import Statistics from './Statistics/index.vue'
import { useConfigStore } from '@/stores/common'
import { getStore } from '@/utils/store'

let permissionsObj = getStore('permissions')


const { setTableSelection } = useConfigStore()
const activeName = ref('1')
const typeActive = ref('a'||'b'||'c')

const tabs = [
	{ label: '养老服务对象', name: '1', tableName: 'dp_service_object' },
	{ label: '养老服务机构', name: '2', tableName: 'dp_service_org_base' },
	{ label: '社区养老服务设施', name: '3', tableName: 'dp_service_facility' },
	{ label: '养老服务运营单位', name: '4', tableName: 'dp_service_org_home' },
	{ label: '养老从业人员', name: '5', tableName: 'dp_foundation_practitioners' },
	{ label: '志愿者', name: '6', tableName: 'dp_volunteer' },
	{ label: '养老专家', name: '7', tableName: 'dp_professor' },
	{ label: '服务商', name: '8', tableName: 'dp_service_provider' },
	{ label: '其他', name: '9', tableName: '' },
]

const onTabClick = (tab) => {
	setTableSelection(false)
}

const tableName = computed(() => {
	return tabs.filter((item) => item.name == activeName.value)[0].tableName
})
const beforeOnLoadFormate = (query) => {
	return new Promise((resolve, reject) => {
		let gatherFinishTimeBetween = ''
		if (query.gatherFinishTimeBetween) {
			gatherFinishTimeBetween = query.gatherFinishTimeBetween.join(',')
		}
		resolve({
			...query,
			gatherFinishTimeBetween,
		})
	})
}

onUnmounted(() => {
	setTableSelection(false)
})
</script>

<style scoped></style>
